#include "widget.h"
#include "ui_widget.h"
#include <QShortcut>
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    ui->label->setText("");
    ui->horizontalSlider->setMinimum(0);
    ui->horizontalSlider->setMaximum(100);
    ui->horizontalSlider->setSingleStep(1);
    ui->horizontalSlider->setValue(0);

    QShortcut* sc1 = new QShortcut(this);
    sc1->setKey(Qt::Key_W);
    connect(sc1,&QShortcut::activated,this,&Widget::add);

    QShortcut* sc2 = new QShortcut(this);
    sc2->setKey(Qt::Key_S);
    connect(sc2,&QShortcut::activated,this,&Widget::sub);
}

Widget::~Widget()
{
    delete ui;
}

void Widget::add()
{
    int value = ui->horizontalSlider->value();
    ui->horizontalSlider->setValue(value + 5);
}

void Widget::sub()
{
    int value = ui->horizontalSlider->value();
    ui->horizontalSlider->setValue(value - 5);
}

void Widget::on_horizontalSlider_valueChanged(int value)
{
    ui->label->setText(QString::number(value));
}
